#include <my_header.h>

/* Usage: ./5_shmctl */
int main(int argc, char *argv[]){                                  
    //1. 
    key_t keytag = ftok("./5_shmctl.c", 10);
    printf("key_t :%d\n", keytag);

    //2.
    int shmid = shmget(keytag, 4096, 0600 | IPC_CREAT);
    ERROR_CHECK(shmid, -1, "shmget");
    printf("shmid :%d\n", shmid);

    // 3.
    char *p = (char *)shmat(shmid, NULL, 0);
    ERROR_CHECK(p, NULL, "shmat");


    // 4. 删除共享内存
    int ret = shmctl(shmid, IPC_RMID, NULL);
    ERROR_CHECK(ret, -1, "shmctl");
    return 0;
}

